package com.sptokentest.controller;


import cn.dev33.satoken.util.SaResult;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sptokentest.pj.dto.RoleDto;
import com.sptokentest.entity.Role;
import com.sptokentest.service.RoleMenuService;
import com.sptokentest.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author young
 * @since 2023年02月03日
 */
@Slf4j
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @Autowired
    private RoleMenuService roleMenuService;
    @GetMapping
    public SaResult getRoleList(){
        LambdaQueryWrapper<Role> lqw = new LambdaQueryWrapper<>();
        lqw.ne(Role::getPer,"superadmin").eq(Role::getStatus,1);
        return SaResult.data(roleService.list(lqw));
    }



    @GetMapping("/alllist")
    public SaResult getAllRole(int page,int pageSize,String rolename){
        return roleService.getPage(page,pageSize,rolename);
    }

    @PostMapping
    public SaResult addRole(@RequestBody RoleDto roleDto){
        return roleService.addRole(roleDto);
    }

    @PutMapping
    public SaResult editRole(@RequestBody RoleDto roleDto){
        return roleService.editRole(roleDto);
    }

    @PostMapping("/setStatus")
    public SaResult setStatus(@RequestBody Role role){
        return roleService.setStatus(role);
    }

    @DeleteMapping("{id}")
    public SaResult delete(@PathVariable Long id){
        return roleService.delete(id);
    }

}

